<template>
	<view class="checkout">
		<view class="navigation">
			<view class="navigation_back" @tap="backref()">
				<uni-icons type="back" size="24" color="#333"></uni-icons>
			</view>
			<view class="navigation_title">
				分类详情
			</view>
		</view>
		<view class="checkout_con">
			<template>
				<view class="content">
					<view class="checkout_con_bt" v-for="(unit, key) in typeList" :key="key">
						<view class="checkout_con_remark">
							<view class="checkout_bt_label">
								分类名称
							</view>
							<view class="checkout_bt_input">
								<input type="text" v-model="unit.name" placeholder="请输入分类名称"
									placeholder-class="placeholder">
							</view>
						</view>
						<view style="margin-left: 10px;">
							<button @tap="deleteFn(key)">删除</button>
						</view>
					</view>
					<view style="margin-top: 20px;" @click="addType()">
						<button type="default">添加分类</button>
					</view>
				</view>
				
			</template>
		</view>
		<view style="position: fixed;
				bottom: 10px;
				left: 0;
				z-index: 5;
				width: 100%;">
			<button type="primary" style="background-color: rgba(255, 141, 26, 1);" @tap="submit()">保存</button>
		</view>
	</view>
</template>

<script>
	import {
		getStoreType,
		deleteType,
		updateType
	} from '../../api/api.js'
	import server_url from '../../api/config.js'
	export default {
		data() {
			return {
				domain: server_url,
				typeList: [],
			};
		},
		methods: {
			addType() {
				let obj = {
					name: ""
				}
				this.typeList.push(obj)
			},
			deleteFn(index) {
				if (this.typeList[index].id) {
					deleteType({
						id: this.typeList[index].id
					}).then(res => {
						if (res.code == 200) {
							this.typeList.splice(index, 1)
						}
					})
				} else {
					this.typeList.splice(index, 1)
				}
			},
			submit() {
				updateType(this.typeList).then(res => {
					uni.showToast({
						title: "操作成功",
						icon: 'none',
						duration: 2000
					})
					this.backref()
				})
			},
			backref() {
				uni.navigateBack({
					delta: 1
				})
			},
		},
		onLoad(e) {
			getStoreType().then(res => {
				this.typeList = res.data
			})
		},
	}
</script>

<style lang="scss">
	page {
		background: #F9FBFC;
	}

	.navigation {
		background: linear-gradient(180deg, rgba(255, 141, 26, 1) 12.5%, rgba(255, 195, 0, 1) 100%);
		width: 100%;
		height: 150rpx;
		padding: 60rpx 24rpx 0;
		text-align: center;
		position: relative;

		.navigation_back {
			position: absolute;
			top: 60rpx;
		}

		.navigation_title {
			color: #333;
			font-size: 36rpx;
		}
	}

	.checkout_con {
		padding: 0 24rpx;
		padding-bottom: 100px;

		.checkout_con_hd {
			padding: 0 32rpx;
			background-color: #fff;
			border-radius: 12rpx;

			.checkout_address {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 32rpx 0;
				border-bottom: 1rpx solid #E8E7E7;
			}

			.checkout_time {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 32rpx 0;

				.checkout_label {
					display: flex;
					align-items: center;
				}

				.about_time {
					margin-left: 30rpx;
					font-size: 30rpx;
					color: #FFB226;
				}

				.checkout_more {
					font-size: 30rpx;
					color: #2E343A;
					font-weight: 500;
				}
			}

			.checkout_label {
				font-size: 30rpx;
				color: #2E343A;
				font-weight: 500;
			}

			.checkout_more {}
		}

		.checkout_con_bd {
			padding: 32rpx;
			background-color: #fff;
			border-radius: 12rpx;
			margin-top: 20rpx;

			.checkout_store_hd {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-bottom: 32rpx;
				border-bottom: 1rpx solid #E8E7E7;

				.checkout_store_name {
					font-size: 30rpx;
					color: #2E343A;
					font-weight: 700;
				}

				.checkout_store_phone {
					image {
						width: 30rpx;
						height: 30rpx;
					}
				}
			}

			.checkout_goods {
				border-bottom: 1rpx solid #E8E7E7;

				.checkout_good {
					position: relative;
					padding: 24rpx 0;
					display: flex;

					.checkout_good_img {
						image {
							width: 120rpx;
							height: 120rpx;
							border-radius: 12rpx;
						}
					}

					.checkout_good_info {
						padding-top: 15rpx;
						margin-left: 24rpx;

						.checkout_good_name {
							font-size: 28rpx;
							color: #2E343A;
							font-weight: 500;
						}

						.checkout_good_type {
							font-size: 24rpx;
							color: #9098A0;
							margin-top: 8rpx;
						}

						.checkout_good_other {
							position: absolute;
							top: 50%;
							transform: translateY(-50%);
							right: 0;
							display: flex;
							flex-direction: column;
							align-items: flex-end;

							.checkout_good_price {
								font-size: 32rpx;
								color: #333333;
								font-weight: 500;
							}

							.checkout_good_num {
								font-size: 24rpx;
								color: #9098A0;
							}
						}
					}
				}
			}

			.checkout_money {
				border-bottom: 1rpx solid #E8E7E7;

				.checkout_lunchbox {
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 20rpx 0;
				}

				.checkout_delivery {
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding-bottom: 20rpx;
				}

				.checkout_money_label {
					font-size: 28rpx;
					color: #9098A0;
					font-weight: 500;
				}

				.checkout_money_price {
					font-size: 28rpx;
					color: #333333;
				}
			}

			.checkout_total_price {
				padding-top: 32rpx;
				text-align: right;
				font-size: 24rpx;
				color: #2E343A;

				text {
					font-size: 32rpx;
					color: #FF2626;
					font-weight: 500;
				}
			}
		}

		.checkout_con_bt {
			// padding: 0 32rpx;
			border-radius: 12rpx;
			margin-top: 24rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.checkout_con_remark {
				flex: 1;
				background-color: #fff;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 32rpx 10px;
				border-bottom: 1rpx solid #E8E7E7;
			}

			.checkout_con_tableware {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 32rpx 0;
			}

			.checkout_bt_label {
				color: #2E343A;
				font-weight: 500;
				font-size: 28rpx;
			}

			.checkout_bt_input {
				input {
					text-align: right;
					color: #2E343A;
					font-weight: 500;
					font-size: 28rpx;

					&.placeholder {
						color: #9098A0;
					}
				}

			}
		}

		.checkout_pay {
			position: relative;
			margin-top: 50rpx;
			display: flex;
			align-items: center;
			width: 100%;
			height: 100rpx;
			border-radius: 100rpx;
			background-color: #3A3635;
			padding-left: 40rpx;

			.checkout_pay_price {
				font-size: 30rpx;
				color: #FFFFFF;
				font-weight: 500;
			}

			.checkout_pay_btn {
				position: absolute;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 30rpx;
				color: #fff;
				top: 0;
				right: 0;
				width: 192rpx;
				height: 100rpx;
				border-top-right-radius: 100rpx;
				border-bottom-right-radius: 100rpx;
				background-color: #2588FF;
			}
		}
	}
</style>
